//
//  Generator.m
//  Generator5x7
//
//  Created by Francis Perea on 12/05/08.
//  Copyright 2008 Francis Perea. All rights reserved.
//

#import "Generator.h"
#import "globales.h"

@implementation Generator 
@synthesize cadena;
@synthesize valores;
 
- (id)init{
  int i;
  self=[super init];
  valores=[[NSMutableArray arrayWithCapacity:COLS] retain]; 
  for(i=0; i<COLS; i++) [valores insertObject:[NSNumber numberWithInt:0] atIndex:i];
  return self;
}
 
- (void)Enciende:(int) x:(int) y: (int) state{
  if (state) {[valores replaceObjectAtIndex:x withObject:[NSNumber numberWithInt:BitOr([[valores objectAtIndex:x] intValue],(128>>y))]];}
  else {[valores replaceObjectAtIndex:x withObject:[NSNumber numberWithInt:BitAnd([[valores objectAtIndex:x] intValue],BitNot(128>>y))]];}
  cadena=[[NSString stringWithFormat:@"{0x%0.2X,0x%0.2X,0x%0.2X,0x%0.2X,0x%0.2X}",[[valores objectAtIndex:0] intValue],[[valores objectAtIndex:1] intValue],[[valores objectAtIndex:2] intValue],[[valores objectAtIndex:3] intValue],[[valores objectAtIndex:4] intValue]] retain];
} 

-(void)dealloc{
 [valores release];
 [cadena release];
 [super dealloc];
}
@end
